<?php

namespace App\Http\Requests;

use \D1M\Payment\Http\Requests\CreateCombinedPaymentRequest as BaseCreateCombinedPaymentRequest;
use Symfony\Component\HttpFoundation\ParameterBag;

class CreateCombinedPaymentRequest extends BaseCreateCombinedPaymentRequest
{

    public function setJson($json)
    {
        $body = $json->all();
        $data = $body['data'] ?? [];

        $json = new ParameterBag($data);

        return parent::setJson($json);
    }

    public function json($key = null, $default = null)
    {
        if (!isset($this->json)) {
            $body = (array)json_decode($this->getContent(), true);
            $data = $body['data'] ?? [];

            $this->json = new ParameterBag($data);
        }

        return parent::json($key, $default);
    }

}